package br.com.ia.struts.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import br.com.enovar.trex.struts.form.TRexBaseForm;

public class VariavelForm extends TRexBaseForm {

	private Integer codigo;
	private Integer codigoAux;
	private String descricao;
	private String novaVariavel;
	private ValorForm valor;

	public Integer getCodigo() {
		return codigo;
	}

	public void setCodigo(Integer codigo) {
		this.codigo = codigo;
	}

	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}
	
	public ValorForm getValor() {
		return valor;
	}

	public void setValor(ValorForm valor) {
		this.valor = valor;
	}

	public String getNovaVariavel() {
		return novaVariavel;
	}

	public void setNovaVariavel(String novaVariavel) {
		this.novaVariavel = novaVariavel;
	}

	public Integer getCodigoAux() {
		return codigoAux;
	}

	public void setCodigoAux(Integer codigoAux) {
		this.codigoAux = codigoAux;
	}

	@Override
	public void reset(ActionMapping arg0, HttpServletRequest arg1) {

		codigo = null;
		descricao = null;
		novaVariavel = null;
		codigoAux = null;
		
		valor = new ValorForm();
		valor.reset(arg0, arg1);
		
		super.reset(arg0, arg1);
	}

	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();

		String param = mapping.getParameter();
		String method = request.getParameter(param);
		if (method.matches("insert|update")) {
			errors = super.validate(mapping, request);
		}

		return errors;
	}

}
